#ifndef		_PAGING_H_
#define		_PAGING_H_

#include	"common.h"
#include	"isr.h"

struct page{
	u32int present	: 1;	/* set if in memory */
	u32int rw	: 1;	/* set if read/write */
	u32int user	: 1;	/* set if in user-mode */
	u32int accessed	: 1;	/* set if accessed */
	u32int dirty	: 1;	/* set if written */
	u32int unused	: 7;	/* unused bits */
	u32int frame	: 20;	/* frame physical addr, shifted right 12 bits */
};

struct page_table{
	struct page pages[1024];
};

struct page_directory{
	struct page_table *tables[1024];
	u32int tables_phys[1024];
	u32int physaddr;
};

void init_paging();
void switch_page_directory(struct page_directory *new_pd);
struct page *get_page(u32int addr, int make, struct page_directory *pd);
void page_fault(struct registers regs);
struct page_directory *clone_directory(struct page_directory *src);
static struct page_table *clone_table(struct page_table *src, u32int *cphys);

void alloc_frame(struct page *ppage, int is_kernel, int is_writeable);

void scan_page_directory(struct page_directory *dir);

#endif		/* _PAGING_H_ */
